package com.tddx.activiti.business.core.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.tddx.activiti.business.core.entity.UserTabColsEntity;

@Repository
public class GentiDao{
	
	private final static String FILTER_COLS = "'ID', 'VC_CREATE', 'VC_UPDATE', 'DT_CREATE', 'DT_UPDATE', 'VC_ORGID', 'VC_SERVER', 'VC_DEL'"; 
	
	@Autowired EntityManager em;
	
	@SuppressWarnings("unchecked")
	public List<UserTabColsEntity> findCols(String tableName, boolean all){
		StringBuffer sb = new StringBuffer(" FROM UserTabColsEntity U");
		sb.append(" WHERE U.pk.tableName=?1");
		if(!all){
			sb.append(" AND U.pk.columnName NOT IN(" + FILTER_COLS + ")");
		}
		Query query = em.createQuery(sb.toString());
		query.setParameter(1, tableName);
		List<UserTabColsEntity> resultList = query.getResultList();
		return resultList;
	}
	
	public List<UserTabColsEntity> findCols(String tableName){
		return findCols(tableName, false);
	}
	
}
